package com.youtills.core.lang;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * TODO - !!!doc me!!!
 *
 * @author ravi.chiluveru
 * @since 23.0 (7/19/14)
 */
public class CollectionUtil {

    public static boolean areEmpty(Collection... collections){
        if(collections == null) {
            return true;
        }
        for(Collection collection : collections) {
            if(!isEmpty(collection)){
                return false;
            }
        }
        return true;
    }

    public static boolean isNotEmpty(Object[] array) {
        return !isEmpty(array);
    }

    public static boolean isEmpty(Object[] array) {
        return array == null || array.length <= 0;
    }

    public static boolean isEmpty(Collection collection){
        return (collection == null || collection.size() == 0);
    }

    public static <E extends Object> boolean areEquals(List<E> list1, List<E> list2) {
        if(ObjectUtil.areEquals(list1, list2) || areEmpty(list1, list2)){
            return true;
        }
        if(isEmpty(list1) || isEmpty(list2) || list1.size() != list2.size()){
            return false;
        }

        for(Iterator it1 = list1.iterator(), it2 = list2.iterator(); it1.hasNext();){
            if(!ObjectUtil.areEquals(it1.next(), it2.next())) {
                return false;
            }
        }

        return true;
    }

    /*
    public static <E extends Object> boolean areEquals(List<E>... lists) {
        if(ArrayUtil.isEmpty(lists) || lists.length == 1){
            return true;
        }

        List<E> first = lists[0];

        for(int i = 1; i < lists.length; i++){
            List<E> current = lists[i];

            if(ObjectUtil.areEquals(first, current)){
                continue;
            }
            if(first.size() != current.size()){
                return false;
            }
        }



        return true;
    }
*/
}
